package database.helpers;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Lesson_Table {

public databas_helper dbHelper;	
public SQLiteDatabase database;
	/**
	 * Assignment table related constants.
	 */
public final static String LESSON_TABLE="Lesson";	
public final static String LESSON_NAME="name";
public final static String LESSON_MSG="MSG";	
public final static String LESSON_TYPE="TYPE";
public final static String LESSON_QSTN="QSTN";
public final static String LESSON_ANS="ANS";
public final static String LESSON_ISCOMPLETE="ISCOMPLETE";
public final static String LESSON_ID="_id";

public Lesson_Table(Context context){
	dbHelper = new databas_helper(context);
	database = dbHelper.getWritableDatabase();
}
public Lesson_Table(databas_helper dbHelper,SQLiteDatabase database){
	this.dbHelper = dbHelper;
	this.database = database;
}

/**\
 * Creates a new LESSON
 	 */
public long addLESSON(String name,String MSG, String TYPE, String QSTN, String ANS, String isComplete){
	ContentValues values = new ContentValues();
	values.put(LESSON_NAME,name);
	values.put(LESSON_MSG,MSG);
	values.put(LESSON_TYPE,TYPE);
	values.put(LESSON_QSTN,QSTN);
	values.put(LESSON_ANS,ANS);	
	values.put(LESSON_ISCOMPLETE,isComplete);	

	return database.insert(LESSON_TABLE, null, values);
}	

public void close() {
	dbHelper.close();
}
/**
 * Fetch all LESSONs
 * @return
 */
public Cursor getAllLESSONs(){
	Cursor mCursor = database.query(true, LESSON_TABLE, new String[]
			{
			LESSON_ID,LESSON_NAME,LESSON_MSG, LESSON_TYPE, LESSON_QSTN,LESSON_ANS,LESSON_ISCOMPLETE},null
			, null, null, null, null, null);
	if (mCursor != null) {
		mCursor.moveToFirst();
	}
	return mCursor;
}
/**
 * 
 */
public int editLESSON(String name,String MSG, String TYPE, String QSTN, String ANS, String isComplete){
	ContentValues values = new ContentValues();
	values.put(LESSON_NAME,name);
	values.put(LESSON_MSG,MSG);
	values.put(LESSON_TYPE,TYPE);
	values.put(LESSON_QSTN,QSTN);
	values.put(LESSON_ANS,ANS);
	values.put(LESSON_ISCOMPLETE,isComplete);
	
	return database.update(LESSON_TABLE, values,LESSON_ID + "=?",new String[]{name});
}

public boolean delete(String name){
	return database.delete(LESSON_TABLE, LESSON_ID + "=" + name, null) > 0;
}
}
